package cn.junechiu.mytodo

import android.app.Application
import io.realm.Realm
import io.realm.RealmConfiguration

/**
 * Created by android on 2017/11/2.
 */
class TodoApp : Application() {

    companion object {
        const val MY_TAG = "TodoApp"
    }

    override fun onCreate() {
        super.onCreate()

        Realm.init(this);
        val config = RealmConfiguration.Builder()
                .name("realm.my_todos") //数据库名
                .encryptionKey(getKey()) //加密
                .deleteRealmIfMigrationNeeded()
                .schemaVersion(1)  // 版本号
                .build()
        Realm.setDefaultConfiguration(config)// 设置默认 RealmConfiguration
    }

    /**
     * 64 bits
     * @return
     */
    private fun getKey(): ByteArray {
        return byteArrayOf(0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1)
    }
}